<?php
/**
 *  +----------------------------------------------------------------------
 *  | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 *  +----------------------------------------------------------------------
 *  | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
 *  +----------------------------------------------------------------------
 *  | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 *  +----------------------------------------------------------------------
 *  | Author: CRMEB Team <admin@crmeb.com>
 *  +----------------------------------------------------------------------
 */

/**
 * 队伍申请
 * @author crud自动生成代码
 * @date 2025/01/15 00:00:00
 */

namespace app\model\crud;

use crmeb\basic\BaseModel;

/**
 * Class TeamApplication
 * @date 2025/01/15
 * @package app\model\crud
 */
class TeamApplicationModel extends BaseModel
{

    /**
     * 表名
     * @var string
     */
    protected $name = 'sq';

    /**
     * 主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 状态常量
     */
    const STATUS_PENDING = 0;  // 等待审核
    const STATUS_APPROVED = 1; // 通过
    const STATUS_REJECTED = 2; // 拒绝

    /**
     * 类型常量
     */
    const TYPE_APPLY = 0;  // 申请
    const TYPE_INVITE = 1; // 邀请

    /**
     * 获取状态文本
     * @param int $status
     * @return string
     */
    public static function getStatusText($status)
    {
        $statusMap = [
            self::STATUS_PENDING => '等待审核',
            self::STATUS_APPROVED => '通过',
            self::STATUS_REJECTED => '拒绝'
        ];
        return $statusMap[$status] ?? '未知状态';
    }

    /**
     * 获取类型文本
     * @param int $type
     * @return string
     */
    public static function getTypeText($type)
    {
        $typeMap = [
            self::TYPE_APPLY => '申请',
            self::TYPE_INVITE => '邀请'
        ];
        return $typeMap[$type] ?? '未知类型';
    }

    /**
     * 关联队伍表
     * @return \think\model\relation\BelongsTo
     */
    public function team()
    {
        return $this->belongsTo(Team::class, 'team_id', 'id');
    }

    /**
     * 关联用户表
     * @return \think\model\relation\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(\app\model\user\User::class, 'uid', 'uid');
    }

    /**
     * 关联报名表
     * @return \think\model\relation\BelongsTo
     */
    public function baoming()
    {
        return $this->belongsTo(\app\model\crud\Baoming::class, 'uid', 'uid');
    }
}
